using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
using DNT.RavenQA.Core.Extensions;
using DNT.RavenQA.Core.Models;

namespace DNT.RavenQA.Web.ViewModels
{
    public class QuestionInput : IQuestionInput
    {
        [HiddenInput(DisplayValue = false)]
        public String TagList
        {
            get { return _tagList; }
            set { _tagList = value; }
        }
        private String _tagList;

        [Required]
        public String Title { get; set; }

        [Required]
        [DataType(DataType.MultilineText)]
        public String Body { get; set; }

        public User Author
        {
            get; set;
        }

        public String[] Tags
        {
            get
            {
                // TODO: we should work a little more on tagging...
                return _tagList.IsNull() 
                           ? null 
                           : _tagList.Trim()
                                 .Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(x => x.ToLower().Trim())
                                 .Where(x => x.Length > 1)
                                 .ToArray();
            }
        }
    }
}